const util = require('../../../utils/util.js');
const rate = wx.getSystemInfoSync().windowWidth / 750;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: getApp().globalData.imgUrls,
    index: '0',
    isShare: false, //是否为分享
    isSucced: true, //是否砍价成功
    rate,
    dataType: '', // 砍价成功或者失败:succedOrfail 没红包 帮砍一🔪helpHackNotCon   我自己分享 myshare
    type: 1,
    showSpecification: false
  },
  goodsInfo() {
    let that = this
    util.API('/bargain/v1.wxbargain/bargain_info_list', {
      bargain_people_id: this.data.options.bargain_people_id,
      type:'1'
    }).then(({
      data,
      msg,
      code
    }) => {
      if (code == 200) {
        this.setData({
          goodsInfo:data,
        })
        util.intervalTime(data.etime, that, 1000) // 倒计时
      } else {
        wx.showToast({
          title: msg + '',
          icon: 'none'
        })
      }
    })

  },
  myevent(e) {
    this.setData({
      showSpecification: e.detail.showSpecification
    })
  },
  clear() {
    this.setData({
      dataType: ''
    })
  },
  helpHack() {
    this.setData({
      dataType: 'helpHack'
    })
  },
  swiper() {
    this.setData({
      index: this.data.index == "0" ? '1' : '0'
    })
  },
  onLoad: function(options) {

    this.setData({
      options
    })
    console.log(options)
    if (options.one_moeny) {
      this.setData({
        dataType: 'mySelf'
      })
    }
    let {
      isSucced,
      isShare,
      type
    } = this.data;

    this.goodsInfo()
    if ((type == 0 && isSucced !== undefined) || (type == 1 && isSucced !== undefined && isShare)) {
      this.setData({
        dataType: 'succedOrfail',
      })

    }
  },
  showSpecification() {
    this.setData({
      showSpecification: !this.data.showSpecification
    })
  },
  preventTouchMove: function(event) {
    return false
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    var that = this
    var query = wx.createSelectorQuery();
    // that.setData({
    //   isShare:true
    // })
    query.selectAll('.scroll-view').boundingClientRect(function(rect) {
      that.setData({
        rect
      })


    }).exec();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage(e) {
    var that = this;
    pid = 1;
    goods_id = 2;
    setTimeout(res => {
      that.setData({
        dataType: 'shareTemplate'
      })
    }, 1000)
    return {
      title: getApp().globalData.app_name,
      imageUrl: '',
      path: `elsePage/pages/bargainDetails/bargainDetails?isShare=${true}&pid=${pid}&goods_id=${goods_id}&bargain_people_id=${this.data.options.bargain_people_id}`,
      success: function(res) {

      },
      fail: function(res) {

      },
    }
  },


})